///////////////////////////////////////////////////////////////////////////////
// Purpose: GDI c++ way
// Todo:
//		Finish classes implementation
// Bugs:
//		None
///////////////////////////////////////////////////////////////////////////////


#ifndef _PHAT_GDI_H
#define _PHAT_GDI_H

#include "phatSS.h"
#include <windows.h>   // include all the windows headers
#include <windowsx.h>  // include useful macros
#include <fstream>

using std::ofstream;
using std::ifstream;
using std::ios;
using std::ios_base;

#define MAIN_CLASS "EDITOR_CLASS"

const int SCREEN_WIDTH = 600;
const int SCREEN_HEIGHT = 450;

const int armorTypeCount = 10;
const int armorClassCount = 10;
const int armorProtCount = 10;

const int weaponCritCount = 3;
const int weaponCtmdCount = 3;
const int weaponDmgCount = 14;

const int itemTypeCount = 4;

INT_PTR CALLBACK NewItemProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK NewWeaponProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK NewArmorProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam,  LPARAM lparam);

void init();
void loop();
void shutdown();

extern HRESULT gResult;
extern RECT gClientRect;

extern HWND gWindow;
extern MSG gMsg;
extern HINSTANCE gInstance;
extern PAINTSTRUCT gPS;
extern HDC	gHDC;

extern HWND gNewItemDlg;
extern HWND gNewWeaponDlg;
extern HWND gNewArmorDlg;

extern HWND gItemTypeCombo;
extern HWND gArmorClassCombo;
extern HWND gArmorTypeCombo;
extern HWND gArmorProtCombo;
extern HWND gWeaponDmgCombo;
extern HWND gWeaponCritCombo;
extern HWND gWeaponCritModCombo;

extern pxSStream ss;

class pxGDI
{
private:
	HWND mWindow;
	HWND mTmp;
	MSG mMsg;
	HINSTANCE mInstance;
	PAINTSTRUCT mPS;
	HDC	mDC;
public:
	pxGDI();
	~pxGDI();

	void setInstance( HINSTANCE tmp ); // for winproc and init win32 access
	void init(string sTitle);
	void init(string sTitle, int x, int y, int w = SCREEN_WIDTH, int h = SCREEN_HEIGHT );
	void destroy();
	void draw();

	HWND addCombo( HWND hParent, string sText, int x, int y, int w, int h, int id, DWORD style = WS_CHILD|CBS_DROPDOWNLIST );
	void drawCombo( HWND hid );
	inline void addComboItem( HWND hid, int iId, string sItem );
	void setComboDef( HWND hid, int iId );

	HWND addButton( string sText, int x,int y, int w, int h, int id, DWORD style = WS_CHILD | WS_VISIBLE );
	void drawButton( HWND hid );
	
	HWND addCheck( string sText, int x,int y, int w, int h, int id, DWORD style = WS_CHILD | WS_VISIBLE);
	void drawCheck( HWND hid );
	
	HWND addRadio( string sText,int x,int y, int w, int h, int id, DWORD style = WS_CHILD | WS_VISIBLE);
	void drawRadio( HWND hid );

	HWND addOwner( string sText,int x,int y, int w, int h, int id, DWORD style = WS_CHILD | WS_VISIBLE );
	void drawOwner( HWND hid );

	void drawBox( RECT &dst );
	void drawBox( int x1, int y1, int x2, int y2 ); // top left, bottom right ( x1, y1 && x2, y2 == top = y left == x. bottom == y2 right == x2. )
	void drawLine( RECT &dst );
	void drawLine( int x1, int y1 ); // start and finish ( x1, y1 )

	void drawText( string sText, int w, int h, RECT &dst );
	void drawText( string sText, int x1, int y1, int w, int h);

	// Accessors
	HWND const getWindow() { return mWindow; }
	HINSTANCE const getInstance() { return mInstance; }
	PAINTSTRUCT const getPS() { return mPS; }
	HDC const getHDC() { return mDC; }
	HWND const getTmp() { return mTmp; } // Shouldn't ever need to use this but just in case

	inline void hide() { ShowWindow( mWindow, SW_HIDE ); }
	inline void show() { ShowWindow( mWindow, SW_SHOW ); }
	inline void minimize() { ShowWindow( mWindow, SW_MINIMIZE ); }
	inline void maximize() { ShowWindow( mWindow, SW_MAXIMIZE ); }
	inline void showMouse() { ShowCursor(true); }
	inline void hideMouse() { ShowCursor(false); }
};

inline void MB( string sMsg, string sTitle = "Error") { MessageBoxA( gWindow, sMsg.c_str(), sTitle.c_str(), MB_OK ); }

#endif